<template>
  <div>
    <Header></Header>
    <div style="margin-top:-20px;">
      <group>
        <p>
          <i class="author_name">{{userInfo.userCustominfo5}}</i>
          <i class="author_info">码字嗨起来</i>
        </p>
      </group>
    </div>
    <div>
      <group>
        <div class="myLibray">
          <cell title="我的作品库" @click.native="goLibrary"  :value="bookList.length" is-link>
          </cell>
        </div>

         <div class="create_btn">
          <x-button type="warn" @click.native="goCreatBook">创建新书</x-button>
         </div>
      </group>
    </div>
    <div>

    </div>
    <Footer></Footer>
  </div>
</template>
<script>
import Header from '@/components/commons/header/header'
import Footer from '@/components/commons/footer/footer'
import bookController from '@/api/bookController/index'
import USER from '@/utils/user'
  export default {
      name: 'authorCenter',
      data(){
        return {
          userInfo: null,
          bookList:[]
        }
      },
       created(){
        this.getLoginInfo();
      },
      components:{Header, Footer},
      methods:{
        getLoginInfo(){ //获取登录信息,如果登录，重定向至登录页面
          var loginInfo = USER.getUserInfo();
          this.userInfo = loginInfo;
          if(loginInfo.isLogin==1){ //0已登录 1未登录
            this.$router.push({name:'login'})
            return false
          }else if(!loginInfo.userCustominfo5){//不存在笔名，非作者，跳转至创建笔名页面
            this.$router.push({name:'penName'})
            return false
          }
          this.getAuthorBook();
        },
        getAuthorBook(){ //获取作者书籍
          bookController.selectByAuthorId().then(response=>{
            if(response.success&&response.data){
              this.bookList = response.data.list
            }
          })
        }, 
        goLibrary(){
          this.$router.push({name:'library'})
        },
        goCreatBook(){//跳转至书籍创建
          this.$router.push({name:'createBookPage'})
        }
      }
  }
</script>

<style scoped>
  .author_name{
    font-size: 16px;
    color: #666;
    padding:0 15px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    line-height:50px;
    max-width: 200px;
    margin-right: 0.5em;
  }
  .author_info {
    font-size: 12px;
    color: #B7B7B7;
    line-height:50px;
    display: inline-block;
    vertical-align: middle;
  }
  .weui-btn_warn{
    background:#FF6100;
  }
  .myLibray{
     border-bottom:1px solid #CDCDCD;
  }
  .create_btn{
    margin-top:10px;
  }
</style>
